# Maintainer: Frederik Schwan <freswa at archlinux dot org>
# Contributor: tectonic-deploy <sasha+tectonic@hackafe.net>
# Contributor: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Jan Tojnar <jtojnar@gmail.com>

pkgname=tectonic
pkgver=0.14.1
pkgrel=4
pkgdesc='Modernized, complete, self-contained TeX/LaTeX engine, powered by XeTeX and TeXLive'
arch=('loong64' 'x86_64')
url='https://tectonic-typesetting.github.io/'
license=('MIT')
depends=('fontconfig' 'harfbuzz-icu' 'openssl')
makedepends=('cargo' 'pkg-config')
options=(!lto)
source=("https://github.com/tectonic-typesetting/tectonic/archive/refs/tags/tectonic@${pkgver}.tar.gz")
b2sums=('94720d6beeef03aae68b1ac70b22995a05be2371176b844dcfbabbadc475e065bd8618c8e937e637394a37349e76fd4373d6732ff2325d50ef11f85582fe1da9')

prepare() {
  cd ${pkgname}-${pkgname}-${pkgver}
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd ${pkgname}-${pkgname}-${pkgver}
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  cargo build --release --locked --features external-harfbuzz
}

check() {
  cd ${pkgname}-${pkgname}-${pkgver}
  export RUSTUP_TOOLCHAIN=stable
  cargo test --release --locked --features external-harfbuzz
}

package() {
  depends+=(
    icu libicuuc.so
    freetype2 libfreetype.so
    zlib libz.so
    graphite libgraphite2.so
    harfbuzz libharfbuzz.so
    libpng libpng16.so
  )
  cd ${pkgname}-${pkgname}-${pkgver}
  install -Dm755 target/release/tectonic "${pkgdir}"/usr/bin/tectonic
  install -Dm644 LICENSE "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}
